<template>
	<view class="cardCabinet u-skeleton">
		<u-navbar title="卡柜" :background="{'backgroundColor':'#fff'}" :borderBottom="false" class="u-skeleton-rect">
			<view slot='right' class="nav-right" @click="tolink">卡片记录</view>
		</u-navbar>
		
		<diy-scroll :Empty='cardList.length ? false : true' :status = 'status'
		 @scrolltolower='scrolltolower'
		 @refresherrefresh='refresherrefresh' :is_display="cardList.length">
			<view class="item u-skeleton-rect" v-for="(v,n) in cardList" :key="n">
				<view class="i-content">
					<image :src="v.icon" mode="heightFix"></image>
					<view class="i-right">
						<view class="name">{{v.title}}</view>
						<view class="num">数量*{{v.surplus_num}}</view>
					</view>
				</view>
			</view>
		</diy-scroll>
		<view class="die-bottom u-skeleton-rect">
			<view class="right">
				<u-button class="primary" ripple-bg-color="rgba(0,0,0,.4)" @click="btn" 
				:ripple="true">出售潮卡</u-button>
			</view>
		</view>
		<u-skeleton :loading="loding" :animation="true" bgColor="#FFF"></u-skeleton>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				// 首次进入加载
				loding: true,
				//加载配置
				page:{
					page:1,
					page_size:8,
				},
				//列表
				cardList:[],
				//判断刷新出来滚动出现的文字
				status:'loadmore',
				is_display:true
			}
		},
		onShow() {
			this.refresherrefresh();
			setTimeout(() => {
				this.loding = false;
			}, 1000)
		},
		methods: {
			//列表刷新事件
			refresherrefresh(callback) {
				this.page = {
					page:1,
					page_size:8,
				},
				this.getCardList(callback);
			},
			// 触底事件
			scrolltolower() {
				console.log("列表触底")
			},
			getCardList(callback){
				this.$http.asyncSendrequest({
					url:'/profile/myCard',
					data:{
						...this.page
					},
					success:res=>{
						if(res.code == '0') {
							if(this.page.page == 1) this.cardList = [];
							if(res.data.length){
								this.cardList = this.cardList.concat(res.data);
								this.page.page += 1;
							} else {
								//下面加载的文字
								this.status = 'nomore';
							}
							if(typeof callback == 'function') callback();
							this.loding = false;
						}
					}
				})
			},
			//出售潮卡
			btn(){
				this.$util.redirectTo('/pages/my/drawCards')
			},
			//前往卡片页面
			tolink(){
				this.$util.redirectTo('/pages/my/cardList')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.item{
		background: #FFFFFF;
		border-radius: 23rpx;
		margin: 30rpx 30rpx 20rpx;
		padding: 34rpx;
		box-sizing: border-box;
		.i-content{
			display: flex;
			image{
				width: 180rpx;
				height: 180rpx;
				border-radius:10rpx;
			}
			.i-right{
				margin-left: 30rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				.name{
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #000000;
				}
				.num{
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #666666;
				}
			}
		}
	}
	.die-bottom {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		// background: #FFFFFF;
		padding: 30rpx;
		.right {
			.primary {
				width: 100%;
				height: 96rpx;
				background: #292929;
				border-radius: 10rpx;
				text-align: center;
				line-height: 96rpx;
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FFFFFF;
			}
		}
	}
	
	.nav-right{
		padding-right: 30rpx;
	}
</style>